<template>
	<view>
		<view class="options" v-if="mode !== 'cash'">
			<view class="opts-type" @click="openOrderSelect">
				<view class="opt-text" v-if="order.order_no">订单号：{{order.order_no}}</view>
				<view class="opt-text" v-else>全部订单</view>
				<image class="icon32" :src="$util.img('/upload/uniapp/xxjk/bonusCenter/arrow_down_fill.png')" mode="">
				</image>
			</view>
			<date-range @change="changeDate"></date-range>
		</view>
		<mescroll-body @init="mescrollInit" @down="downCallback" @up="upCallback">
			<!-- 数据列表 -->
			<view class="list-box" v-if="dataList.length > 0">
				<view class="list-item" v-for="item in dataList">
					<template v-if="mode == 'x_value'">
						<!-- x数字资产记录 -->
						<view class="">
							<view class="order-head">
								<image class="icon48"
									:src="$util.img('/upload/uniapp/xxjk/bonusCenter/order_dh_gold.png')" mode=""
									v-if="item.from_type == 'goldpoints'"></image>
								<image class="icon48" v-else
									:src="$util.img('/upload/uniapp/xxjk/bonusCenter/order_dh_cashCoupon.png')" mode="">
								</image>
								<view class="order-title">{{item.type_name}}</view>
							</view>
							<view class="order-remark">{{item.remark}}</view>
							<view class="order-no">订单号 {{item.type_tag}}</view>
							<view class="order-time">时间 {{item.create_time}}</view>
						</view>
						<view class="">
							<view class="order-value">
								{{item.account_data > 0 ? '+' + item.account_data : item.account_data}}
							</view>
							<!-- <view class="order-value-rest">剩余{{item.surplus_bonus_amount}}</view> -->
						</view>
					</template>
					<template v-else-if="mode == 'cash'">
						<!-- 数字资产记录 -->
						<view class="">
							<view class="order-head">
								<image class="icon48"
									:src="$util.img('/upload/uniapp/xxjk/bonusCenter/icon_dh_x_value.png')" mode=""
									v-if="item.from_type == 'x_value'"></image>
								<image class="icon48" v-else
									:src="$util.img('/upload/uniapp/xxjk/bonusCenter/icon_xf_coupon.png')" mode="">
								</image>
								<view class="order-title">{{item.type_name}}</view>
							</view>
							<view class="order-remark">{{item.remark}}</view>
							<view class="order-time">时间 {{item.create_time}}</view>
						</view>
						<view class="">
							<view class="order-value">
								{{item.account_data > 0 ? '+' + item.account_data : item.account_data}}
							</view>
							<!-- <view class="order-value-rest">剩余{{ item.surplus_bonus_amount}}</view> -->
						</view>
					</template>
					<template v-else>
						<!-- 分红额度消耗记录 -->
						<view class="">
							<view class="order-head">
								<image class="icon48"
									:src="$util.img('/upload/uniapp/xxjk/bonusCenter/order_speed.png')" mode=""
									v-if="item.type == 1"></image>
								<image class="icon48" v-else
									:src="$util.img('/upload/uniapp/xxjk/bonusCenter/order_static.png')" mode="">
								</image>
								<view class="order-title">{{item.type_name}}</view>
							</view>
							<view class="order-no">订单号 {{item.order_no}}</view>
							<view class="order-time">时间 {{item.create_time}}</view>
						</view>
						<view class="">
							<view class="order-value">{{item.value > 0 ?'+' + item.value : item.value}}</view>
							<!-- <view class="order-value-rest">剩余{{item.surplus_value}}</view> -->
						</view>
					</template>

				</view>
			</view>
			<view v-else><ns-empty :isIndex="!1" :fixed="false" text="暂无数据"></ns-empty></view>
		</mescroll-body>
		<order-select ref="orderSelect" @change="changeOrder"></order-select>
	</view>
</template>

<script>
	import MescrollMixin from "@/components/mescroll/mescroll-mixins.js";
	import orderSelect from './components/order-select';
	import dateRange from './components/date-range';
	export default {
		mixins: [MescrollMixin],
		components: {
			orderSelect,
			dateRange
		},
		data() {
			return {
				listParams: {
					start: '',
					end: '',
					order_no: ''
				},
				order: {},
				dataList: [],
				mode: ''
			}
		},
		onLoad(options) {
			if (options.order_no) {
				this.order.order_no = options.order_no;
				this.listParams.order_no = options.order_no;
			}
			// mode参数
			// mode=bonus||''：分红记录
			// mode=x_value:x数字资产记录
			// mode=cash:数字资产（数字资产）记录
			this.mode = options.mode || '';
			let title = '分红额度消耗记录'
			if (this.mode == 'x_value') {
				title = 'x数字资产记录'
			} else if (this.mode == 'cash') {
				title = '数字资产记录'
			}
			uni.setNavigationBarTitle({
				title
			})

		},
		methods: {
			openOrderSelect() {
				this.$refs.orderSelect.open()
			},
			changeOrder(e) {
				this.order = e.value;
				this.changeOptions({
					order_no: this.order.order_no
				})
			},
			changeDate(e) {
				this.changeOptions({
					start: e.value[0] || '',
					end: e.value[1] || ''
				})
			},
			upCallback(mescroll) {
				// 分红额度消耗记录
				let url = '/goldpoints/api/Record/amountRecordList'
				if (this.mode == 'x_value') {
					// x数字资产记录
					url = '/goldpoints/api/Record/getXvalueRecordList'
				} else if (this.mode == 'cash') {
					//数字资产记录
					url = '/goldpoints/api/Record/getCouponRecordList'
				}

				this.$api.sendRequest({
					url,
					data: {
						...this.listParams,
						page: mescroll.num,
						page_size: mescroll.size
					},
					success: (res) => {
						if (res.code == 0) {
							let list = res.data.list.map(item => {
								let type_name = '';
								let create_time = item.create_time || item.creat_time;
								if (item.from_type) {
									if (this.mode == 'cash') {
										type_name = item.type_name;
									} else {
										type_name = {
											'goldpoints': '金数字资产兑换X数字资产',
											'exchange_value': '兑换数字资产',
											'exchange_balance': '兑换消费券',
											'order': '消费',
											'x_value': 'X数字资产兑换'
										} [item.from_type]
									}
								} else {
									type_name = ['订单生成', '团队加速', '直推', '平级奖励加速'][item
										.type
									];
								}


								return {
									...item,
									type_name,
									create_time: this.$util.timeStampTurnTime(create_time)
								}
							})
							if (mescroll.num == 1) this.dataList = [];
							this.dataList = [...this.dataList, ...list];
							this.mescroll.endSuccess(this.dataList.length);
						} else {
							this.mescroll.endErr();
						}
					},
					fail: () => {
						this.mescroll.endErr();
					}
				})
			},
			changeOptions(data) {
				this.listParams = {
					...this.listParams,
					...data
				}
				this.mescroll.resetUpScroll();
				this.mescroll.scrollTo(0, 0);
			}
		}
	}
</script>

<style lang="scss" scoped>
	@import './public/css/common.scss';


	.list-item {
		margin: 20rpx 24rpx;
		padding: 28rpx 18rpx;
		display: flex;
		justify-content: space-between;
		align-items: flex-start;
		width: 702rpx;
		background: #FFFFFF;
		border-radius: 16rpx 16rpx 16rpx 16rpx;

		.order-head {
			display: flex;
			justify-content: flex-start;
			align-items: center;

			.icon48 {
				width: 48rpx;
				height: 48rpx;
				margin-right: 18rpx;
			}

			.order-title {
				font-weight: 500;
				font-size: 32rpx;
				color: #222222;
				line-height: 38rpx;
			}
		}

		.order-remark,
		.order-no,
		.order-time {
			margin-left: 66rpx;
			margin-top: 16rpx;
			font-size: 26rpx;
			color: #999999;
			line-height: 30rpx;
		}

		.order-remark {
			font-size: 28rpx;
			color: #222222;
		}

		.order-no,
		.order-time {
			font-size: 26rpx;
			color: #999999;
			line-height: 30rpx;
		}

		.order-value {
			font-family: Helvetica, Helvetica;
			font-weight: bold;
			font-size: 34rpx;
			color: #222222;
			line-height: 40rpx;
			text-align: center;
		}

		.order-value-rest {
			display: flex;
			justify-content: center;
			align-items: center;
			margin-top: 20rpx;
			width: 130rpx;
			height: 46rpx;
			background: #FFF3F1;
			border-radius: 40rpx 40rpx 40rpx 40rpx;
			font-weight: 400;
			font-size: 24rpx;
			color: #FC311A;
			line-height: 28rpx
		}
	}

	.options {
		width: 750rpx;
		height: 240rpx;
		background: #FFFFFF;
		padding: 24rpx;
	}
</style>